package org.dyndns.opendemogroup.optimizer;

import static org.junit.Assert.*;
import org.junit.Test;

/**
 * A class to test the class GenericGenerationalGeneticAlgorithm
 */
public class GenericGenerationalGeneticAlgorithmTest
{

	/**
	 * Tests the <i>areApproximatelyEqual</i> method with a typical scenario.
	 */
	@Test
	public void areApproximatelyEqual_TypicalEqual ( )
	{
		double one = 1.0;
		double two = 1.25;
		double delta = 0.5;
		boolean actual =
			GenericGenerationalGeneticAlgorithm.areApproximatelyEqual ( one,
				two, delta );
		boolean expected = true;
		assertEquals ( expected, actual );
	}

	/**
	 * Tests the <i>areApproximatelyEqual</i> method with a typical scenario.
	 */
	@Test
	public void areApproximatelyEqual_TypicalNotEqual ( )
	{
		double one = 1.0;
		double two = 1.25;
		double delta = 0.05;
		boolean actual =
			GenericGenerationalGeneticAlgorithm.areApproximatelyEqual ( one,
				two, delta );
		boolean expected = false;
		assertEquals ( expected, actual );
	}

	/**
	 * Tests the <i>areApproximatelyEqual</i> method with an error condition of
	 * providing a delta that is equal to zero.
	 */
	@Test ( expected = IllegalArgumentException.class )
	public void areApproximatelyEqual_DeltaEqualZero ( )
	{
		double one = 0.0;
		double two = 0.0;
		double delta = 0.0;
		GenericGenerationalGeneticAlgorithm.areApproximatelyEqual ( one, two,
			delta );
	}

	/**
	 * Tests the <i>areApproximatelyEqual</i> method with an error condition of
	 * providing a delta that is less than zero.
	 */
	@Test ( expected = IllegalArgumentException.class )
	public void areApproximatelyEqual_DeltaLessThanZero ( )
	{
		double one = 0.0;
		double two = 0.0;
		double delta = -1.0;
		GenericGenerationalGeneticAlgorithm.areApproximatelyEqual ( one, two,
			delta );
	}

}
